package com.zz.Interface.studentMannger;

import java.util.ArrayList;

public class Operator2 implements StudentOperator {
    @Override
    public void printAllInfo(ArrayList<Student> students) {
        int girlNum = 0;
        int boyNum = 0;
        System.out.println("=====全部学生信息=====");
        for(int i = 0; i < students.size(); i++){
            Student student = students.get(i);
            System.out.println("学生的姓名：" + student.getName() + "性别："
                    + student.getSex() + "成绩" + student.getScore());
            if(student.getSex() == '男'){
                girlNum++;
            }else{
                boyNum++;
            }
        }
        System.out.println("男生人数为：" + boyNum + "，女生人数为：" + girlNum);
    }

    @Override
    public void printAverageScore(ArrayList<Student> students) {
        double scoreAll = 0.0;
        double max = 0;
        double min = students.get(0).getScore();
        System.out.println("=======学生平均分======");
        for(int i = 0; i < students.size(); i++){
            Student student = students.get(i);
            scoreAll += student.getScore();
            if(max < student.getScore()){
                max = student.getScore();
            }
            if(min > student.getScore()){
                min = student.getScore();
            }
        }
        double average = (scoreAll-min-max)/(students.size()-2);
        System.out.println("去掉最高分和最低分后全班平均成绩是：" + average);
    }
}
